package id.co.rho.scoring.cid.client.widgets;

import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridViewConfig;

import id.co.rho.scoring.cid.client.model.ChangeTrackingModel;

public class DirtyAwareEditorGrid<T extends ModelData> extends EditorGrid<T> {

    /**
     * Creates a new editor grid.
     *
     * @param store the store
     * @param cm    the column model
     */
    public DirtyAwareEditorGrid(ListStore store, ColumnModel cm) {
        super(store, cm);
        init();
    }

    private void init() {
		GridViewConfig config = new GridViewConfig() {
			@Override
			public String getRowStyle(ModelData model, int rowIndex,
					ListStore<ModelData> ds) {
				if(model instanceof ChangeTrackingModel) {
					ChangeTrackingModel ctm = (ChangeTrackingModel) model;
					if(ctm.isDirty()) {
						return "grid-row-dirty";
					}
				}
				return super.getRowStyle(model, rowIndex, ds);
			}			
		};
		
		getView().setViewConfig(config);
	}
}
